package com.liy.supercloud.server.gateway.task;

import com.liy.framework.common.redis.utils.RedisUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@AutoConfigureAfter({RedisUtils.class})
public class RolePermissionTimer {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RedisUtils redisUtils;

    public static Map<Object, Object> sharePermission = new ConcurrentHashMap();
    public static Map<Object, Object> rolePermission = new ConcurrentHashMap();


    @Scheduled(
            fixedRate = 300000L
    )
    public void updateSharePermission() {
        Map<Object, Object> obj = this.redisUtils.hmget("PER:COMM");
        if (obj != null) {
            sharePermission = obj;
        }

        this.log.info("Update shared permissions successfully: " + sharePermission.size());
    }

    @Scheduled(
            fixedRate = 300000L
    )
    public void initRolesPermission() {
        Map<Object, Object> obj = this.redisUtils.hmget("PER:COMM");
        if (obj != null) {
            sharePermission = obj;
        }

        this.log.info("Update roles permissions successfully: " + sharePermission.size());
    }
}
